package com.dm.service;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dm.util.VariantUtil;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Variant;

public class BaseServiceImpl extends WindowServiceImpl implements DMPlugin {
	private static final String bind_window = "BindWindow"; 
	private static final String lockInput = "LocakInput";
	private static final String lock_mouseRect = "LockMouseRect";
	private static final String un_bind_window = "UnBindWindow";
	private static final String get_base_path = "GetBasePath";
	private Logger log = LoggerFactory.getLogger(BaseServiceImpl.class);
	@Override
	public long bindWindow(int hwnd, String display, String mouse, String keypad, int mode,
			ActiveXComponent acComponent) {
		String method = "BindWindow";
		Variant[] variants = VariantUtil.varToVariants(hwnd,display,mouse,keypad,mode);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+": {},{},{},{},{} and result:{}", hwnd,display,mouse,keypad,mode,result);
		return result.getInt();
	}
	@Override
	public long lockInput(int lock, ActiveXComponent acComponent) {
		String method = "LockInput";
		Variant[] variants = VariantUtil.varToVariants(lock);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+": {}, and result:{}", lock,result);
		return result.getLong();
	}
	@Override
	public long lockMouseRect(int x1, int y1, int x2, int y2, ActiveXComponent acComponent) {
		String method = "LockMouseRect";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+": {},{},{},{} and result:{}", x1,y1,x2,y2,result);
		return result.getLong();
	}
	@Override
	public long unBindWindow(ActiveXComponent acComponent) {
		String method = "UnBindWindow";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getInt();
	}
	@Override
	public String getBasePath(ActiveXComponent acComponent) {
		String method = "GetBasePath";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getString();
	}
	@Override
	public long getID(ActiveXComponent acComponent) {
		String method = "GetId";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getLong();
	}
	@Override
	public long getLastError(ActiveXComponent acComponent) {
		String method = "GetLastError";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getInt();
	}
	@Override
	public String getPath(ActiveXComponent acComponent) {
		String method = "GetPath";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getString();
	}
	@Override
	public long setDisplayInput(int mode, ActiveXComponent acComponent) {
		String method = "SetDisplayInput";
		Variant[] variants = VariantUtil.varToVariants(mode);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getLong();
	}
	@Override
	public long setPath(String path, ActiveXComponent acComponent) {
		String method = "SetPath";
		Variant[] variants = VariantUtil.varToVariants(path);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{}  and result:{}",path,result);
		return result.getLong();
	}
	@Override
	public String ver(ActiveXComponent acComponent) {
		String method = "Ver";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getString();
	}
	@Override
	public long keyDown(int vkCode, ActiveXComponent acComponent) {
		String method = "KeyDown";
		Variant[] variants = VariantUtil.varToVariants(vkCode);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{}  and result:{}",vkCode,result);
		return result.getInt();
	}
	@Override
	public long keyDownChar(String keyStr, ActiveXComponent acComponent) {
		String method = "KeyDownChar";
		Variant[] variants = VariantUtil.varToVariants(keyStr);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+": {} and result:{}",keyStr,result);
		return result.getLong();
	}
	@Override
	public long keyPress(int vkCode, ActiveXComponent acComponent) {
		String method = "KeyPress";
		Variant[] variants = VariantUtil.varToVariants(vkCode);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{}  and result:{}",vkCode,result);
		return result.getInt();
	}
	@Override
	public long keyPressChar(String str, ActiveXComponent acComponent) {
		String method = "KeyPressChar";
		Variant[] variants = VariantUtil.varToVariants(str);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+": {} and result:{}",variants,result);
		return result.getLong();
	}
	@Override
	public long keyUp(int vk_code, ActiveXComponent acComponent) {
		String method = "KeyUp";
		Variant[] variants = VariantUtil.varToVariants(vk_code);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+": {} and result:{}",vk_code,result);
		return result.getInt();
	}
	@Override
	public long keyUpChar(String str, ActiveXComponent acComponent) {
		String method = "KeyUpChar";
		Variant[] variants = VariantUtil.varToVariants(str);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{}  and result:{}",str,result);
		return result.getLong();
	}
	@Override
	public long leftClick(ActiveXComponent acComponent) {
		String method = "LeftClick";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getInt();
	}
	@Override
	public long leftDoubleClick(ActiveXComponent acComponent) {
		String method = "LeftDoubleClick";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getInt();
	}
	@Override
	public long leftDown(ActiveXComponent acComponent) {
		String method = "LeftDown";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getLong();
	}
	@Override
	public long leftUp(ActiveXComponent acComponent) {
		String method = "LeftUp";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getLong();
	}
	@Override
	public long moveR(int rx, int ry, ActiveXComponent acComponent) {
		String method = "MoveR";
		Variant[] variants = VariantUtil.varToVariants(rx,ry);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+": {},{} and result:{}",rx,ry,result);
		return result.getLong();
	}
	@Override
	public long moveTo(int x, int y, ActiveXComponent acComponent) {
		String method = "MoveTo";
		Variant[] variants = VariantUtil.varToVariants(x,y);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+": {},{} and result:{}",x,y,result);
		return result.getInt();
	}
	@Override
	public String moveToEx(int x, int y, int w, int h, ActiveXComponent acComponent) {
		String method = "MoveToEx";
		Variant[] variants = VariantUtil.varToVariants(x,y,w,h);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{}  and result:{}",x,y,w,h,result);
		return result.getString();
	}
	@Override
	public long rightClick(ActiveXComponent acComponent) {
		String method = "RightClick";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getLong();
	}
	@Override
	public long rightDown(ActiveXComponent acComponent) {
		String method = "RightDown";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getLong();
	}
	@Override
	public long rightUp(ActiveXComponent acComponent) {
		String method = "RightUp";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getLong();
	}
	@Override
	public long wheelDown(ActiveXComponent acComponent) {
		String method = "WheelDown";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getLong();
	}
	@Override
	public long wheelUp(ActiveXComponent acComponent) {
		String method = "WheelUp";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":  and result:{}",result);
		return result.getLong();
	}
	@Override
	public long capture(int x1, int y1, int x2, int y2, String file, ActiveXComponent acComponent) {
		String method = "Capture";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2,file);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{},{}  and result:{}",x1,y1,x2,y2,file,result);
		return result.getInt();
	}
	@Override
	public long cmpColor(int x, int y, String color, double sim, ActiveXComponent acComponent) {
		String method = "CmpColor";
		Variant[] variants = VariantUtil.varToVariants(x,y,color,sim);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{}  and result:{}",x,y,color,sim,result);
		return result.getLong();
	}
	@Override
	public String findColorEx(int x1, int y1, int x2, int y2, String color, double sim, int dir,
			ActiveXComponent acComponent) {
		String method = "FindColorE";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2,color,sim,dir);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{},{},{}  and result:{}",x1,y1,x2,y2,color,sim,result);
		return result.getString();
	}
	@Override
	public String findPicE(int x1, int y1, int x2, int y2, String pic_name, String delta_color, double sim, int dir,
			ActiveXComponent acComponent) {
		String method = "FindPicE";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2,pic_name,delta_color,sim,dir);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{},{},{},{},{}  and result:{}",x1,y1,x2,y2,pic_name,delta_color,sim,dir,result);
		return result.getString();
	}
	@Override
	public String getAveHSV(int x1, int y1, int x2, int y2, ActiveXComponent acComponent) {
		String method = "GetAveHSV";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{}  and result:{}",x1,y1,x2,y2,result);
		return result.getString();
	}
	@Override
	public String getAveRGB(int x1, int y1, int x2, int y2, ActiveXComponent acComponent) {
		String method = "GetAveRGB";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{}  and result:{}",x1,y1,x2,y2,result);
		return result.getString();
	}
	@Override
	public String getColor(int x, int y, ActiveXComponent acComponent) {
		String method = "GetColor";
		Variant[] variants = VariantUtil.varToVariants(x,y);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{}  and result:{}",x,y,result);
		return result.getString();
	}
	@Override
	public long isDisplayDead(int x1, int y1, int x2, int y2, int t, ActiveXComponent acComponent) {
		String method = "isDisplayDead";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2,t);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{},{}  and result:{}",x1,y1,x2,y2,t,result);
		return result.getLong();
	}
	@Override
	public String findStrE(int x1, int y1, int x2, int y2, String string, String color_format, double sim,
			ActiveXComponent acComponent) {
		String method = "FindStrE";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2,string,color_format,sim);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{},{},{},{}  and result:{}",x1,y1,x2,y2,string,color_format,sim,result);
		return result.getString();
	}
	@Override
	public String findStrEx(int x1, int y1, int x2, int y2, String string, String color_format, double sim,
			ActiveXComponent acComponent) {
		String method = "FindStrEx";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2,string,color_format,sim);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{},{},{},{}  and result:{}",x1,y1,x2,y2,string,color_format,sim,result);
		return result.getString();
	}
	@Override
	public String findStrFastE(int x1, int y1, int x2, int y2, String string, String color_format, double sim,
			ActiveXComponent acComponent) {
		String method = "FindStrFastE";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2,string,color_format,sim);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{},{},{},{}  and result:{}",x1,y1,x2,y2,string,color_format,sim,result);
		return result.getString();
	}
	@Override
	public String findStrFastEx(int x1, int y1, int x2, int y2, String string, String color_format, double sim,
			ActiveXComponent acComponent) {
		String method = "FindStrFastEx";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2,string,color_format,sim);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{},{},{},{}  and result:{}",x1,y1,x2,y2,string,color_format,sim,result);
		return result.getString();
	}
	@Override
	public long getDictCount(int index, ActiveXComponent acComponent) {
		String method = "GetDictCount";
		Variant[] variants = VariantUtil.varToVariants(index);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{}  and result:{}",index,result);
		return result.getLong();
	}
	@Override
	public long getNowDict(ActiveXComponent acComponent) {
		String method = "GetNowDict";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+": and result:{}",result);
		return result.getLong();
	}
	@Override
	public String ocr(int x1, int y1, int x2, int y2, String color_format, double sim, ActiveXComponent acComponent) {
		String method = "Ocr";
		Variant[] variants = VariantUtil.varToVariants(x1,y1,x2,y2,color_format,sim);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{},{},{},{},{} and result:{}",x1,y1,x2,y2,color_format,sim,result);
		return result.getString();
	}
	@Override
	public int setDict(int index, String file, ActiveXComponent acComponent) {
		String method = "SetDict";
		Variant[] variants = VariantUtil.varToVariants(index,file);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{},{} and result:{}",index,file,result);
		return result.getInt();
	}
	@Override
	public long useDict(int index, ActiveXComponent acComponent) {
		String method = "UseDict";
		Variant[] variants = VariantUtil.varToVariants(index);
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+":{} and result:{}",index,result);
		return result.getInt();
	}
	@Override
	public long getScreenDepth(ActiveXComponent acComponent) {
		String method = "GetScreenDepth";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+": and result:{}",result);
		return result.getLong();
	}

	@Override
	public String getClipboard(ActiveXComponent acComponent) {
		String method = "GetClipboard";
		Variant[] variants = VariantUtil.varToVariants();
		Variant result = acComponent.invoke(method, variants);
		log.debug(method+": and result:{}",result);
		return result.getString();
	}

	@Override
	public long leftClick(int x, int y, ActiveXComponent acComponent, int count) {
		this.moveTo(x, y, acComponent);
		for (int i = 0; i < count; i++) {
			leftClick(acComponent);
		}
		return 0;
	}
	
}
